<!--  -->
<template>
  <div class="goods-list-item" @click="itemClick">
    <img :src="showImage" alt="" @load="imageLoad">
    <div class="goods-info">
      <p>{{goodsItem.title}}</p>
      <span class="price">￥:{{goodsItem.price}}</span>
      <span class="collect">{{goodsItem.cfav}}</span>
    </div>
  </div>
</template>

<script>
export default {
  name: 'GoodsListItem',
  props: {
    goodsItem: {
      type: Object,
      default() {
        return {}
      }
    }
  },
  data() {
    return {

    }
  },
  computed: {
    showImage(){ // 展示图片
      return this.goodsItem.image || this.goodsItem.show.img
    }
  },
  // 生命周期 - 创建完成（访问当前this实例）
  created() {
    // console.log(1111111)
    // console.log(this.goodsItem)
  },
  // 生命周期 - 挂载完成（访问DOM元素）
  mounted() {

  },
  methods: {
    imageLoad() {
      this.$bus.$emit('itemImageLoad')
    },
    itemClick(){
      this.$router.push('/detail/'+ this.goodsItem.iid)
    }

  }
}
</script>
<style scoped>
/* @import url(); 引入css类 */
  .goods-list-item {
    width: 48%;
    box-sizing: border-box;
    padding-bottom: 40px;
    position: relative;
  }
  .goods-list-item img {
    width: 100%;
    border-radius: 10px;
  }
  .goods-info {
    position: absolute;
    font-size: 12px;
    left: 0;
    right: 0;
    bottom: 5px;
  }
  .goods-info p {
    overflow: hidden;
    white-space: nowrap;
    text-overflow:ellipsis;
  }
  .goods-info .price{
    color: var(--color-high-text);
  }
  .goods-info .collect {
    position: relative;
    padding-left: 25px;
  }
  .goods-info .collect::before {
    content: '';
    position: absolute;
    left: 10px;
    top: -1px;
    width: 14px;
    height: 14px;
    background: url("~assets/img/home/collect_icon.png") 14px 0/14px 14px;
  }


</style>
